<template>
<div class="wrapper" ref="wrapper">
    <div class="list">
        <div class="current">
            <p class="title">当前城市</p>
            <div class="city">
                <div class="btn">
                    {{this.$store.state.letter}}
                </div>
            </div>
        </div>
        <div class="current">
            <p class="title">热门城市</p>
            <div class="city">
                <div class="btn" v-for="(item,index) of hotCities" :key="index">
                {{item.name}}
                </div>
            </div>
        </div>
        <div class="current" v-for="(item,index) of cities" :key="index">
            <p class="title" :ref="index">{{index}}</p>
            <div class="name city" v-for="(city,inx) of item" :key="inx">{{city.name}}</div>
        </div>
    </div>
</div>
</template>
<script>
import BScroll from "better-scroll";
export default {
    name:"CityList",
    props:['hotCities','cities'],
    mounted() {
    this.$nextTick(() => {
      this.scroll = new BScroll(this.$refs.wrapper, {});
    });
  },
  computed:{
      letter(){
          return this.$store.state.letter
      }
  },
  watch:{
      letter(){
           var elment = this.$refs[this.letter][0];
      this.scroll.scrollToElement(elment);
      }
  }
}
</script>
<style lang="scss" scoped>
.wrapper {
  width: 100%;
  max-height: 1000px;
  overflow: hidden;
  position: relative;
  margin-top: 170px;
}
.list{
    // position: absolute;
    margin-top: 165px;
    width:100%;
    background-color: #eee;
}
.title{
    margin-left: 20px;
    height:55px;
    line-height:55px;
    font-size: 18px;
    color: #666;
}
.city{
    background-color: #fff !important;
    // height: 80px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}
.city .btn{
    width: 180px;
    height: 55px;
    line-height: 55px;
    text-align: center;
    border:1px solid #ccc;
    font-size: 18px;
    border-radius: 15px;
    margin-left: 40px;
     color: #666;
     margin-top:12px;
     margin-bottom:12px;
}
.name{
    widows: 100%;
    height: 60px;
    color: #666;
    border-bottom: 1px solid #ccc;
    font-size: 18px;
    padding-left: 15px;
}

</style>

